package com.tongle.frs.web;

import com.tongle.frs.common.redis.RedisUtil;
import com.tongle.frs.model.User;
import com.tongle.frs.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;

import java.util.concurrent.TimeUnit;

/**
 * @author hyson
 * @create 2017-02-17 11:42
 */
@RestController
public class UserController {
    @Reference(version = "1.0.0")
    HelloService helloservice;
    @Autowired
    RedisTemplate<String, String> redisTemp;

    @RequestMapping("/user/{id}")
    public User view(@PathVariable("id") Long id) {
        User user = new User();
        user.setId(id);
        user.setName("raysky");
        helloservice.sayHello("raysky");
        RedisUtil redisUtil = new RedisUtil();
        redisUtil.setRedisTemplate(redisTemp);
        //5秒后过期未nil
        redisUtil.set("hyson", "myself", 5L, TimeUnit.SECONDS);
        return user;
    }
}
